package com.webapp.models;

import java.io.Serializable;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;

public class FormBean implements Serializable {

	private String email = "";
	private String password = "";
	private String confirmpassword = "";
	private String salutation = "";
	private String name = "";
	private String language = "";
	private String middlename = "";
	private String companyindustry = "";
	private String lastname = "";
	private String jobttitle = "";
	private String bPhone = "";
	private String jobRole = "";
	private String company2 = "";
	private String getproducts = "";
	private String country = "";
	private String city = "";
	private String company3 = "";
	private String state = "";
	private String address = "";
	private String postal = "";
	private String address2 = "";
	private String bPhone2 = "";
	private String sendPromo = "";
	private List theList = new ArrayList();
	
	public String getSalutation() {
		return salutation;
	}

	public void setSalutation(String salutation) {
		theList.add(salutation);
		this.salutation = salutation;
	}

	public String getName() {
		
		return name;
	}

	public void setName(String name) {
		theList.add(name);
		this.name = name;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		
		this.language = language;
	}

	public String getMiddlename() {
		theList.add(middlename);
		return middlename;
	}

	public void setMiddlename(String middlename) {
		this.middlename = middlename;
	}

	public String getCompanyindustry() {
		theList.add(companyindustry);
		return companyindustry;
	}

	public void setCompanyindustry(String companyindustry) {
		this.companyindustry = companyindustry;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		theList.add(lastname);
		this.lastname = lastname;
	}

	public String getJobttitle() {
		return jobttitle;
	}

	public void setJobttitle(String jobttitle) {
		theList.add(jobttitle);
		this.jobttitle = jobttitle;
	}

	public String getbPhone() {
		return bPhone;
	}

	public void setbPhone(String bPhone) {
		theList.add(bPhone);
		this.bPhone = bPhone;
	}

	public String getJobRole() {
		return jobRole;
	}

	public void setJobRole(String jobRole) {
		theList.add(jobRole);
		this.jobRole = jobRole;
	}

	public String getCompany2() {
		return company2;
	}

	public void setCompany2(String company2) {
		theList.add(company2);
		this.company2 = company2;
	}

	public String getGetproducts() {
		return getproducts;
	}

	public void setGetproducts(String getproducts) {
		theList.add(getproducts);
		this.getproducts = getproducts;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		theList.add(country);
		this.country = country;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		theList.add(city);
		this.city = city;
	}

	public String getCompany3() {
		return company3;
	}

	public void setCompany3(String company3) {
		theList.add(company3);
		this.company3 = company3;
	}

	public String getState() {
	
		return state;
	}

	public void setState(String state) {
		theList.add(state);
		this.state = state;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		theList.add(address);
		this.address = address;
	}

	public String getPostal()
	{
		return postal;
	}
	
	public void setPostal(String postal)
	{
		theList.add(postal);
		this.postal = postal;
	}
	
	public String getAddress2() {
		return address2;
	}

	public void setAddress2(String address2) {
		theList.add(address2);
		this.address2 = address2;
	}

	public String getbPhone2() {
		return bPhone2;
	}

	public List getList() {
		return theList;
	}
	public void setbPhone2(String bPhone2) {
		theList.add(bPhone2);
		this.bPhone2 = bPhone2;
	}

	public String getSendPromo() {
		return sendPromo;
	}

	public void setSendPromo(String sendPromo) {
		theList.add(sendPromo);
		this.sendPromo = sendPromo;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
		theList.add(email);
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
		theList.add(password);
	}

	public String getConfirmpassword() {
		return confirmpassword;
	}

	public void setConfirmpassword(String confirmpassword) {
		this.confirmpassword = confirmpassword;
	}

	// return a map of errors!
	public boolean IsValid(Map<String, String> errorMap) {
		
		if(email.equals("") || !email.contains("@"))
			errorMap.put("email", "Email is invalid (should be like something@yahoo.com)\n");
				
		if(password.equals("") || confirmpassword.equals("") || !password.equals(confirmpassword))
			errorMap.put("password", "Password does not match\n");
		
		if (name.equals(""))
			errorMap.put("name", "First name field is empty\n");
	
		if (language.equals(""))
			errorMap.put("language", "Language preference not selected\n");
		
		if (companyindustry.equals(""))
			errorMap.put("companyindustry", "Company industry preference not selected\n");
		
		if (lastname.equals(""))
			errorMap.put("lastname", "Last name field is empty\n");
		
		if (jobttitle.equals(""))
			errorMap.put("jobtitle", "Job title is empty\n");
		
		// Did not include the dashes between digits (assume it is there).
		if (bPhone.equals("") || bPhone.length()< 13)
			errorMap.put("bPhone", "Business Phone field is empty or inputted improperly (should be like (718)555-3421)\n");
		
		if (jobRole.equals(""))
			errorMap.put("jobRole", "Job role field is empty\n");
		
		if (company2.equals(""))
			errorMap.put("company2", "Company name field is empty\n");
		
		if (country.equals(""))
			errorMap.put("country", "Country preference is not selected\n");
		
		if (city.equals(""))
			errorMap.put("city", "City field is empty\n");
		
		// 224 is 'USA'
		if (state.equals("") && country.equals("224"))
			errorMap.put("state", "Need to declare a state if residing in United States\n");
		
		if (address.equals(""))
			errorMap.put("address", "Address field is empty\n");
		
		if (postal.equals("") || postal.length() < 5)
			errorMap.put("postal", "Postal field is empty or has been improperly inputted (must be 5 digit zip or area code)\n");
		
		if (bPhone2.equals("") || bPhone.length() < 13)
			errorMap.put("bPhone2", "Business Phone field is empty or inputted incorrectly (should be like (718)555-3421)\n");
		
		// if error
		if(errorMap.isEmpty())
			return true;
		else
			return false;
	}
	
	//Overloaded method in case error return is not needed
	public boolean isValid(){
		if(email.equals("") || !email.contains("@"))
			return false;
				
		if(password.equals("") || confirmpassword.equals("") || !password.equals(confirmpassword))
			return false;
		
		if (name.equals(""))
			return false;
	
		if (language.equals(""))
			return false;
		
		if (companyindustry.equals(""))
			return false;
		
		if (lastname.equals(""))
			return false;
		
		if (jobttitle.equals(""))
			return false;
		
		// Did not include the dashes between digits (assume it is there).
		if (bPhone.equals("") || bPhone.length()< 13)
			return false;
		
		if (jobRole.equals(""))
			return false;
		
		if (company2.equals(""))
			return false;
		
		if (country.equals(""))
			return false;
		
		if (city.equals(""))
			return false;
		
		// 224 is 'USA'
		if (state.equals("") && country.equals("224"))
			return false;
		
		if (address.equals(""))
			return false;
		
		if (postal.equals("") || postal.length() < 5)
			return false;
		
		if (bPhone2.equals("") || bPhone.length() < 13)
			return false;
		
		// if no error
		return true;
	}
}
